//
//  Status.swift
//  新浪微博01
//
//  Created by 李国伟 on 15/12/11.
//  Copyright © 2015年 李国伟. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 缩略图
    var pic_urls: [[String: String]]?
    ///转发微博的Status
    var retweeted_status: Status?
    /// 用户信息
    var user: User?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
  
    //拦截user转化成模型
    override func setValue(value: AnyObject?, forKey key: String) {
        
        // 判断 key 是否是 user
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                
                user = User(dict: dict)
            }
            return
        }
        
        //判断是否是转发
        if key == "retweeted_status" {
            
            if let dict = value as? [String: AnyObject] {
                
                retweeted_status =  Status(dict: dict)
            }
            
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["created_at", "id", "text", "source","user","retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}

